#ifndef CCTPREQUESTMODE_H
#define CCTPREQUESTMODE_H

#include <iostream>
#include"ThostFtdcMdApi.h"
#include"ThostFtdcMdSpiImpl.h"
#include"ThostFtdcTraderApi.h"
#include"ThostFtdcTraderSpiImpl.h"
#include"cctpthrdsavetick.h"
#include"../CommUtil/ComFun.h"
#include"../CommUtil/oracledao.h"
#include"ThostFtdcUserApiStruct.h"

class CCTPRequestMode
{
public:
    CCTPRequestMode(void);
    ~CCTPRequestMode(void);

    void InitTradeObject();
    void InitMdObject();
    void ConnectToMdServer();
    void ConnectToTradeServer();

    void SubscribeMarketData();
    void StartSaveMarketInfoThrd();

    bool GetInstruments();
    bool MatchThread();

    void OnRtnDepthMarketData(CThostFtdcDepthMarketDataField *pDepthMarketData);


private:
    //针对每个合约 固定存入指定的线程中处理
    QMap<QString,int> m_MapMatchThrd;

    CThostFtdcMdApi * m_pmdUserApi;
    CThostFtdcTraderApi * m_pTradeUserApi;
    CThostFtdcMdSpiImpl * m_pThostFtdcMdSpiImpl;
    CThostFtdcTraderSpiImpl * m_pThostFtdcTraderSpiImpl;

    QString m_strUserName;
    QString m_strBrokerID;
    QString m_strPassword;

    CCTPThrdSaveTick m_thrdSave[WORK_QUEUE];
    //保存日K的线程
    CCTPThrdSaveTick m_thrdSave1Day;
    //保存5分钟K线的线程
    CCTPThrdSaveTick m_thrdSave5MinKLine;
    //保存1分钟K线的线程
    CCTPThrdSaveTick m_thrdSave1MinKLine;

    std::vector<QString>  m_InstrumentsVector;
    QMap<QString,ContractType> m_contracttype;

    QString m_DaoName;
    OracleDAO* m_Dao;
};

#endif // CCTPREQUESTMODE_H
